package com.wxl.micro.service.gateway.filters;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 *
 * 局部过滤器和全局过滤器区别：
 * 局部：局部针对某个路由， 需要在路由中进行配置
 * 全局：针对所有路由请求， 一旦定义就会投入使用
 *
 * GlobalFilter 接口和 GatewayFilter 有一样的接口定义，只不过， GlobalFilter 会作用于所有路由
 *
 *
 */
@Component
public class GlobalLogFilter implements GlobalFilter{

    Logger log = LoggerFactory.getLogger(this.getClass());

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        log.info("全局日志过滤器：{}",exchange.getRequest().getPath().value());
        return chain.filter(exchange);
    }
}
